const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    switchList:[
      // {title:'已提交',dataList:[{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}]},
      // {title:'未提交',dataList:[{},{},{},{},{},{},{},{},{},{},{}]},
    ],
    selectIndex:0, //0 已提交 1未提交
    needLine:true,
    isShowDetail:true,
    pageData:{},
    homeworkInfos:{},
    // totalNum:0,
    // completedNum:0

    countPic:9,//上传图片最大数量
    showImgUrl: "", //路径拼接，一般上传返回的都是文件名，
    uploadImgUrl:'',//图片的上传的路径
    imgDetailPics:[], //作业页面显示的图片
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: "作业详情"
    })
    this.setData({
      pageData:JSON.parse(options.info)
    })
    //console.log("=2233====="+JSON.stringify(this.data.pageData))
    if(this.data.pageData.pictureUrl!=null){
      console.log("======+str=="+JSON.stringify(this.data.pageData.pictureUrl.join(',')));
      var dataStr = this.data.pageData.pictureUrl.join(',');
      this.setData({
        imgDetailPics:dataStr.split(',')
      })
    }
    console.log("=2====="+JSON.stringify(this.data.imgDetailPics))
   // this.showDate();
    
  },

  // showDate(){
  //   var dateCom =  this.selectComponent("#date-select");
    
  //   dateCom.onShowAlert(null,null,['发布作业']);
    
  // },
  didClickIndex(e){
    let index = e.detail;
   this.setData({
     selectIndex:index
   })
    console.log('打印：'+index)
  },

  clickItem(val){
    console.log("学生位置==="+val.currentTarget.dataset.index);
    if(this.data.selectIndex == 1){ //未提交
      wx.showToast({
        title: '该学生未提交作业',
        icon: 'none',
        duration: 2000,
        mask:true
      })
    }else{//已提交作业学生列表
      let index = val.currentTarget.dataset.index;
      
      // var info  = this.data.switchList[this.data.selectIndex].dataList[index]
      //  info.classId =this.data.pageData.classId||1
      //  info.homeworkId = this.data.pageData.homeworkId
      //  var data = Object.assign(info,this.data.pageData)
      //  console.log("data===="+JSON.stringify(data))
      console.log('接口数据a='+JSON.stringify(this.data.pageData));
      console.log('接口数据v='+JSON.stringify(this.data.switchList[this.data.selectIndex].dataList[index]));

      wx.navigateTo({
        url: '../../pages/record/approvalWorksTeach?workInfo='+JSON.stringify(this.data.pageData)+"&stuInfo="+JSON.stringify(this.data.switchList[this.data.selectIndex].dataList[index])+"&isMark="+this.data.switchList[this.data.selectIndex].dataList[index].isMark,
     })
    }
  },

  // didClickIndex(e){
  //   let index = e.detail;
  //  this.setData({
  //    selectIndex:index
  //  })
  //  if(index == 0 && (this.data.leftDataList==null || this.data.leftDataList.length<=0)){
  //    this.setData({
  //     sex:"1",//1男生 2女
  //    })
  //    //this.getListData()
  //  }else if(index == 1 && (this.data.rightDataList==null || this.data.rightDataList.length<=0)){
  //   this.setData({
  //     sex:"2",//1男生 2女
  //    })
  //    this.getListData()
  //  }
  //   console.log('打印：'+index)
  // },





  didClickUp(){
    this.setData({
      isShowDetail:false
    })
  },

  didClickDown(){
    this.setData({
      isShowDetail:true
    })
  },


 //获取作业提交相关接口
 getHomeworkInfo(){
   var that = this;
  wx.showLoading({
    title: '数据加载中...',
    icon: 'none',
  })

  var datas = {
    classId:this.data.pageData.classId!=null?this.data.pageData.classId:1,
    homeworkId:this.data.pageData.homeworkId,
  }
  console.log('接口参数='+JSON.stringify(datas));
  app.api.getHomeworkInfo(datas).then(rest => {
    wx.hideLoading()
    console.log('接口数据a='+JSON.stringify(rest));
    if(rest&&rest.success){ 

      // var vTompletedNum = rest.data.completedList!=null?rest.data.completedList.length:0;
      // var vTotalNum = vTompletedNum + rest.data.undoneList!=null?rest.data.undoneList.length:0
      this.setData({
        homeworkInfos:rest.data,
        // totalNum:vTotalNum,
        // completedNum:vTompletedNum
      })

      let temp1 ={
        title:"已提交",
        dataList:rest.data.completedList
      }
      let temp2 ={
        title:"未提交",
        dataList:rest.data.undoneList
      }
      this.setData({
        ['switchList[0]']:temp1,
        ['switchList[1]']:temp2,
      })

      console.log('接口数据aaa='+JSON.stringify(this.data.homeworkInfos));
      console.log('接口数据abbb='+JSON.stringify(this.data.switchList));
    }else{
      console.log('接口数据=='+rest.errMsg)
      wx.showToast({
        title: rest.errMsg||'网络异常，请稍后重试！！',
        icon: 'none',
        duration: 2000,
        mask:true
      })
    }
  })
  .catch(r => {
    wx.hideLoading()
    console.error(r)
    wx.showToast({
      title: '网络异常，请稍后重试！',
      icon: 'none',
      duration: 2000,
      mask:true
    })
  })
},


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getHomeworkInfo()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})